package com.project.service.impl;

import com.github.pagehelper.PageInfo;
import com.project.bean.ProjectBean;
import com.project.mapper.IProcessMapper;
import com.project.mapper.IProjectMapper;
import com.project.service.IProcessService;
import com.project.service.IProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.Period;
import java.util.List;
@Service
@Transactional
public class ProjectServiceImpl implements IProjectService {
    @Autowired
    private IProjectMapper mapper;
    @Autowired
    private IProcessMapper prMapper;
    @Override
    public PageInfo<ProjectBean> findByItem(int pageNO, String name, String status, String rule) {
        if (rule.equals("不限")){
            rule =null;
        }
        PageInfo<ProjectBean> info = PageInfo.of(mapper.findByItem(name, status, rule));
        return info;
    }

    @Override
    public void add(ProjectBean projectBean) {
        mapper.add(projectBean);

    }

    @Override
    public ProjectBean findById(int id) {
//        ProjectBean projectBean = mapper.findById(id);
//        projectBean.setNowLn(mapper.countAll(id));
//        projectBean.setRemainDay(Period.between(projectBean.getStartDate(),projectBean.getDeliveryDate()).getDays()+"");
        return mapper.findById(id);
    }

    @Override
    public List<ProjectBean> findByFinish() {
        return mapper.findByFinish();
    }

    @Override
    public void finishProject(int id) {
        mapper.finishProject(id, LocalDate.now());
        prMapper.finishProject(id,LocalDate.now());

    }
}
